package org.jground.zk.util;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.zul.AbstractListModel;
import org.jground.codetable.*;
import org.jground.util.*;

public class CodeTableListModel extends AbstractListModel {

    private Codetable codeTable;

    public CodeTableListModel(Codetable codeTable) {
        this.codeTable = codeTable;
    }

    public Object getElementAt(int index) {
        return codeTable.get(index);
    }

    public int getSize() {
        return codeTable.size();
    }

    public List<Integer> indexesByCodes(String... codes) {
        ArrayList<Integer> indexes = new ArrayList<Integer>(1);
        for (int i = 0; i < codeTable.size(); i++) {
            CodetableElement cte = codeTable.get(i);
            if (ArrayUtils.contains(codes, cte.getCode())) {
                indexes.add(i);
            }
        }
        return indexes;
    }

}
